
//
//  AddressController.m
//  Demo
//
//  Created by 微光星芒 on 2017/11/17.
//  Copyright © 2017年 微光星芒. All rights reserved.
//

#import "AddressController.h"
#import "AddressCell.h"
#import "AddressALiPayCell.h"

static NSString * const kAddressCellIdentifier = @"AddressCell";
static NSString * const kAddressALiPayCellIdentifier = @"AddressALiPayCell";


#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width


@interface AddressController () <UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *mainTableView;

@end

@implementation AddressController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initUI];
}

#pragma mark 按钮点击时间
- (void)helpBtnAction:(UIButton *)btn{
    NSLog(@"展示帮助");
}


#pragma mark  表视图代理方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 4) { //支付宝cell高度
        return 126;
    }
    return 132; //银行cell高度
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.row == 4) {
        
        AddressALiPayCell *cell = [tableView dequeueReusableCellWithIdentifier:kAddressALiPayCellIdentifier];
        return cell;
    }
    
    AddressCell *cell = [tableView dequeueReusableCellWithIdentifier:kAddressCellIdentifier];
    return cell;
}



- (void)initUI{
    
    self.title = @"收款地址管理";
    
    self.navigationItem.rightBarButtonItem = [self createRightBarButtonItemWithTitle:@"帮助"];
    
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;;

    [_mainTableView registerNib:[UINib nibWithNibName:@"AddressCell" bundle:nil] forCellReuseIdentifier:kAddressCellIdentifier];
    
    [_mainTableView registerNib:[UINib nibWithNibName:@"AddressALiPayCell" bundle:nil] forCellReuseIdentifier:kAddressALiPayCellIdentifier];
}


- (UIBarButtonItem *)createRightBarButtonItemWithTitle:(NSString *)title{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 56, 28)];
    
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem * barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    [btn addTarget:self action:@selector(helpBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    return barButtonItem ;
}

@end
